﻿<div class="west_all" style="padding:0px">&nbsp;</div>
<div class="center_all" style="padding:0px">
<div class="center" style="height:100%;padding:0px;">
    <div class="center_n" style="background-image: url(./../theme/default/images/main/pane_top.png)"></div>
    <div class="center_e" style="background-image: url(./../theme/default/images/main/pane_left.png)"></div>
    <div class="center_c" style="">    
        <div class="center_c_c" style="padding:0px">
            <table id="GridTable"></table>
        </div>
    </div>
    <div class="center_w" style="background-image: url(./../theme/default/images/main/pane_right.png)"></div>
    <div class="center_s" style=" background-image: url(./../theme/default/images/main/pane_bottom.png)"></div>
</div>
<form id="searchForm" onSubmit="return false">
<div id="queryForm">
<input type="hidden" id="businessProcessId" name="businessProcess.id" value="${businessProcess.id}">
<input type="hidden" id="listId" name="list.id" value="${list.id}">
<input type="hidden" id="id" name="id">
<#if businessInstance?? && !businessInstance.id?? && businessInstance.parentInstance??>
<input type="hidden" name="parentInstance.id" value="${businessInstance.parentInstance.id}">
</#if>
<#if list.linkOperate??>
<input type="hidden" name="linkOperate" value="${list.linkOperate}">
</#if>
<input type="hidden" id="status" name="taskStatus">
<input type="hidden" id="functionId" name="function.id" value="${function.id}">
</div>
 </form>
<form id="hiddenForm">
<#if fieldMap??>
	<#list fieldMap?keys as key>
		<#if fieldMap[key].field??>
		<input type=hidden name="fieldMap['${key}'].field.id" <#if fieldMap[key].field.id??> value="${fieldMap[key].field.id}"</#if>>
		<input type=hidden id="${key}" name="fieldMap['${key}'].value" <#if fieldMap[key].value??> value="${fieldMap[key].value}"</#if>></input>
		<input type=hidden id="${key}" name="fieldMap['${key}'].entityId" <#if fieldMap[key].entityId??> value="${fieldMap[key].entityId}"</#if>></input>
		</#if>
	</#list>
</#if>
</form>
<script language="javascript">
// JavaScript Document
$(function(){
    layout();
    loadGrid();
    /*reloadTree("1");*/
    $("#all_search").inputStyle({
        operatorId:"all_search_Opt",
        operatorType:"img",
        operatorImg:"./../theme/default/images/main/search.png",
        controllerWidth:200,
        operatorFun:showMenu
    });
    
    ${"$('#search')"}.click(function(){
          $('#GridTable').datagrid("options").url=TDQS.CONTEXT_PATH+'business/list.action?tdqssid='+TDQS.SESSION_ID;
          $('#GridTable').datagrid("tdqsLoad",getFormParams('searchForm'));
        });
    document.getElementsByTagName('form')[0].onkeydown = function(e){
          var e = e || event;
          var keyNum = e.which || e.keyCode;
          if(keyNum==13){
              ${"$('#search')"}.click();
              return false;
          }
          return true;
        };
        $('#GridTable').datagrid("autoresize");
});

function process(funcId,messageType,message,forwardType) {
      ${"$('#functionId')"}.val(funcId);
      var url = TDQS.CONTEXT_PATH+'business/process?tdqssid='+TDQS.SESSION_ID+ "&function.id="+${"$('#functionId')"}.val()+"&businessProcess.id="+${"$('#businessProcessId')"}.val()+"&list.id="+$('#listId').val();
      <#if list.isPassParams?? && list.isPassParams=="1">
      url = url+'&'+$('#hiddenForm').serialize();
      </#if>
      if($('#id').val()!='') {
          url += ("&id="+$('#id').val());
      }
      if($('#status').val()!='') {
          url += ("&taskStatus="+$('#status').val());
      }
      url += "&date="+new Date().toLocaleString();
      if(!message||message=='') {
            message = '确定要执行操作吗？';
      }
      if(messageType && messageType=='1') {
          jConfirm(message, '确认对话框 ', function(r) {
                        if(r){
                            if(forwardType && forwardType=='2') {
                                executeAjaxFunction(url);
                            }
                            else {
                                document.location.href = url;
                            }
                        }else{
                            return false;
                        }
          });
      }
      else {
            if(forwardType && forwardType=='2') {
                executeAjaxFunction(url);    
            }
            else {
                document.location.href = url;
            }
      }
}
function executeAjaxFunction(url) {
    $.tdqsAjax({
        type: "post",
        dataType: "json",
        url: url,
        success:function(json) {
            if(json.data && json.data.type && json.data.type=='2' && json.data.resultData){
                jAlert(json.data.resultData,'提示',function(){
                    $('#GridTable').datagrid("tdqsReload");
                });
            }
            else {
                $('#GridTable').datagrid("tdqsReload");
            }
            ${"$('#id')"}.val('');
            $('#GridTable').datagrid('clearSelections');
            $('input','.datagrid-header-check').each(function(){
                $(this).removeAttr("checked");
            });
        }
    });
}
function processRowFunc(id,funcId,status,messageType,message,forwardType) {
     $('#id').val(id);
     if(status && status!=''){
     	$('#status').val(status);
     }
     process(funcId,messageType,message,forwardType);
}
function showDetail(id,funcId,title) {
	$('#id').val(id);
	${"$('#functionId')"}.val(funcId);
    var url = TDQS.CONTEXT_PATH+'business/process?tdqssid='+TDQS.SESSION_ID+ "&function.id="+${"$('#functionId')"}.val()+"&businessProcess.id="+${"$('#businessProcessId')"}.val()+"&list.id="+$('#listId').val();
    if($('#id').val()!='') {
        url += ("&id="+$('#id').val());
    }
    url += "&date="+new Date().toLocaleString();
    if(parent && parent.addTabPage) {
    	parent.addTabPage(url,title+'关联专题');
    } else {
    	document.location.href = url;
    }
}

function processCommonFunc(funcId,isBatch,messageType,message,forwardType) {
   if(isBatch && isBatch=='1') {
          var select = $('#GridTable').datagrid('getSelections');
          var primaryValue = "";
          var status = "";
          if (select && select != "") {
              for ( var i = 0; i < select.length; i++) {
                  if (i < select.length - 1) {
                       primaryValue += select[i].id+ ",";
                       if(select[i].status && select[i].status.id) {
                       		status += select[i].status.id+ ",";
                       }
                                
                   } else {
                        primaryValue += select[i].id;
                        if(select[i].status && select[i].status.id) {
                       		status += select[i].status.id;
                       }
                   }
               }
           }
           if(!primaryValue || primaryValue=='') {
              jAlert('请选择${businessProcess.businessObj.desc}！','提示',function(){});
              return false;
           }
        $('#id').val(primaryValue);
        $('#status').val(status);
    }
      process(funcId,messageType,message,forwardType);
}

//z_tree data start
var zTree1;

var setting = {
    showLine: true
};

var curType = '0';
var curLi;
function reloadTree(type) {
    if (curLi) curLi.removeClass("focus");
    var setting1 = clone(setting);
    setting1.treeNodeKey = "id";
    setting1.treeNodeParentKey = "pId";
    clone(zNodes);
    setting1.isSimpleData = false;
    zNodes1 = clone(zNodes);
    
    if (!type) type = (curType=='0') ? '1' : curType;
    setting1.nameCol = "name";
    setting1.expandSpeed = "";
    setting1.fontCss = $("#font_1").attr("checked") ? setFont : {};
    
    if (type=="1") {
        setting1.showLine = true;
        curLi = $("#defaultStyle");
        
    } 

    curLi.addClass("focus");
    curType = type;
    zTree1 = $("#treeDemo").zTree(setting1, zNodes1);
    $("#nameCode").html(setting1.nameCol);
    $("#expandSpeedCode").html(setting1.expandSpeed);
    $("#fontCssCode").html($("#font_1").attr("checked") ? "setFont" : "{}");
    $("#isSimpleDataCode").html(setting1.isSimpleData + "");
    
}
function showMenu(){
    
}
function loadGrid(){
     ${"$('#GridTable')"}.datagrid({            
            url:TDQS.CONTEXT_PATH+'business/list.action?ajaxLoadType=1&tdqssid='+TDQS.SESSION_ID,
            queryParams:getFormParams('searchForm'),
            idField:"id",
            pageNumber:${pager.currentPage?default(1)},
            pageSize:${pager.pageSize?default(1)},
            sortName: "<#if sort??>${sort}</#if>",
            sortOrder: "<#if order??>${order}</#if>",
            frozenColumns:[[{
                 field : 'ck',
                 checkbox : true,
                 defaultValue : ''
                },{
                 field : 'indexer',
                 title : '序号',
                 width : 50,
                 formatter:${"$"}.fn.datagrid.defaults.indexFormatter,
                 edit : false,
                 align : 'center',
                 defaultValue : ''
                }
                <#list listFields as listField>
                <#if listField.frozen?? && listField.frozen=='1'>
                ,{
                 field : '${listField.field.name}',
                 title : '${listField.title}',
                 width : ${listField.width},
                 editor : 'text',
                 defaultValue : <#if listField.defaultValue??>'${listField.defaultValue}'<#else>''</#if>,
                 align : <#if listField.align??>'${listField.align}'<#else>'center'</#if>,
                 edit : true,
                 formatter:function(value, row, index){
                     var fieldValue = '';
                     if(row.fieldMap['${listField.field.name}'] && row.fieldMap['${listField.field.name}'].value) {
                         fieldValue = row.fieldMap['${listField.field.name}'].value;
                     }
                     var displayValue = '';
                     if(row.fieldMap['${listField.field.name}'] && row.fieldMap['${listField.field.name}'].displayValue) {
                         displayValue = row.fieldMap['${listField.field.name}'].displayValue;
                     }
                     if(displayValue && displayValue!=null && displayValue!='') {
                         return displayValue;
                     }
                     if(fieldValue=='') {
                         fieldValue = '&nbsp;';
                     }
                     if(row.editStatusFunction && row.editStatusFunction.id) {
                          var value = "<a href=\"javascript:void(0);\" onclick=\"showDetail('"+row.id+"','"+row.editStatusFunction.id+"','"+row.editStatusFunction.displayName+"');return false;\">"+fieldValue+"</a>";
                         return value;
                     }
                     return fieldValue;
                 }
                } 
                </#if>
                </#list>
                ] ],
            columns:[ [ 
                <#assign index=0>
                <#list listFields as listField>
                <#if !listField.frozen?? || listField.frozen=='0'>
                <#if index gt 0>
                ,
                </#if>
                {
                    field : '${listField.field.name}',
                     title : '${listField.title}',
                     width : ${listField.width},
                     editor : 'text',
                     defaultValue : <#if listField.defaultValue??>'${listField.defaultValue}'<#else>''</#if>,
                     align : <#if listField.align??>'${listField.align}'<#else>'center'</#if>,
                     edit : true,
                     sortable : <#if listField?? && listField.sortable?? && listField.sortable=="1">true<#else>false</#if>,
                     formatter:function(value, row, index){
                          var fieldValue = '';
                         if(row.fieldMap['${listField.field.name}'] && row.fieldMap['${listField.field.name}'].value) {
                             fieldValue = row.fieldMap['${listField.field.name}'].value;
                         }
                         var displayValue = '';
                         if(row.fieldMap['${listField.field.name}'] && row.fieldMap['${listField.field.name}'].displayValue) {
                             displayValue = row.fieldMap['${listField.field.name}'].displayValue;
                         }
                         if(displayValue && displayValue!=null && displayValue!='') {
                             return displayValue;
                         }
                         if(fieldValue=='') {
                             fieldValue = '&nbsp;';
                         }
                         return fieldValue;
                     }
                }
                <#assign index=index+1>
                </#if>
                </#list>
                <#if list.allowOperColumn?? && list.allowOperColumn=="1">
                ,            
                 {    
                    field : 'opt',
                    title : '操作',
                    width : 200,
                    align : 'center',
                    rowspan : 2,
                    formatter:function(value, row, index){
                        var opers = '';
                        if(row && row.listFunctionList) {
                        	var status = '';
                        	if(row.status && row.status.id) {
                        		status = row.status.id;
                        	}
                            for(var i=0,l=row.listFunctionList.length;i<l;i++) {
                                 var func = row.listFunctionList[i];
                                 var funcId = '';
                                 var messageType = '';
                                 var message = '';
                                 var funcName = '';
                                 var forwardType = '';
                                 if(func) {
                                     if(func.id) {
                                         funcId = func.id;
                                     }
                                     if(func.messageType) {
                                         messageType = func.messageType;
                                     }
                                     if(func.message) {
                                         message = func.message;
                                     }
                                     if(func.displayName) {
                                         funcName = func.displayName;
                                     }
                                     else if(func.desc) {
                                         funcName = func.desc;
                                     }
                                     if(func.forwardType) {
                                         forwardType = func.forwardType;
                                     }
                                 }
                                 if(!row.editStatusFunction || row.editStatusFunction.id !== func.id) {
                                 	opers += "<a href=\"javascript:void(0)\" onclick=\"javascript:processRowFunc('"+row.id+"','"+funcId+"','"+status+"','"+messageType+"','"+message+"','"+forwardType+"');return false;\">"+funcName+"</a>";
                                 	opers += "&nbsp;&nbsp;";
                                 }
                            }
                        }
                        if(opers=='') {
                             opers = '&nbsp;';
                        }
                        return opers; 
                    }
                }
                </#if>
                ] ],
            operations:{}
        });
            
}

function resizeDatagrid(){
    $('#GridTable').datagrid("autoresize");
}
var mainLayout;
var centerContentLayout;
var contentLayout;
function layout(){
        var toggle_we        = '<div class="btnToggler_we"></div>'
        , toggle_w            = '<div class="btnToggler_w"></div>'
        , btnToggler_se        = '<div class="btnToggler_se"></div>'
        , btnToggler_s        = '<div class="btnToggler_s"></div>'
        
        $('body').layout({
            defaults:{
                onresize_end:    resizeDatagrid
                ,onclose_end:    resizeDatagrid  
            }
            ,center:{
                paneSelector:    ".center_all" 
            }
        });

        $('.center_all').layout({
            defaults:{
                onresize_end:    resizeDatagrid
                ,onclose_end:    resizeDatagrid  
            }
            ,center:{
                paneSelector:    ".center" 
            }
        });
        $(".west_s,.west_n,.west_e,.west_w").css({overflow:"hidden"});

        $('div.center').layout({
            center__paneSelector:    ".center_c" 
        ,   north__size:    3
        ,    north__paneSelector:    ".center_n" 
        ,    north__spacing_open:    0
        ,    north__spacing_closed:    0        
        ,   south__paneSelector:    ".center_s"
        ,    south__size:    3
        ,    south__maxSize:            3
        ,    south__spacing_open:    0
        ,    south__spacing_close:    0
        ,    south__closable:        false
        ,    south__resizable:        false
        ,   east__size:    3
        ,    east__paneSelector:    ".center_e" 
        ,    east__spacing_open:    0
        ,    east__spacing_closed:    0        
        ,   west__size:    3
        ,    west__paneSelector:    ".center_w" 
        ,    west__spacing_open:    0
        ,    west__spacing_closed:    0    
        });
        $(".center_s,.center_n,.center_e,.center_w").css({overflow:"hidden"});

        $('div.center_c').layout({
            center:{
                paneSelector:    ".center_c_c" 
            }
         });
        
}
</script>                                                                                                                                                                                                                                                                                       